
import 'package:dio/dio.dart';
import 'package:stroke_customer/comm/net/AppServer.dart';
import 'package:stroke_customer/comm/net/ServiceUri.dart';
import 'package:stroke_customer/model/comm/CommMenu.dart';

 main(){
   Future data =HttpUtil.get(ServiceUri.comCustomerMenu);
    data.then((d){
      print("oooooooooooo");
      // ignore: unused_local_variable
      Map<String, dynamic> jsonMap =d;
      print(d.runtimeType.toString());
      print(d.runtimeType);
      print("oooooooooooo"+"xxxxxxx");
      CommMenu menu =new  CommMenu.fromJson(jsonMap);
      print("menu code is "+menu.code);
      print("menu msg is "+menu.msg);
      print("menu is "+menu.data[1].menuName);
      print(jsonMap);
    });
 }

class HttpUtil{


  static Dio dio =new Dio();
  static  Options options =new Options();

   static get(uri, {data, options, cancelToken}) async {
     String url=AppServer.appServer+uri;
     DateTime date1= new DateTime.now();
    print('get请求启动! url：$url ');
    Response response;
    try {
      response = await dio.get(
        url,
        data: data,
        cancelToken: cancelToken,
      );
      print('get请求成功!response.data：${response.headers}');
      print('get请求成功!response.data：${response.data}');
    } on DioError catch (e) {
      print("*******error*****");
      if (CancelToken.isCancel(e)) {
        print('get请求取消! ' + e.message);
      }
      print('get请求发生错误：$e');
    }
    DateTime date2= new DateTime.now();

    int cost =date2.millisecondsSinceEpoch-date2.millisecondsSinceEpoch;

     print('get请求成功222222!response.data：${response.data}');

    return response.data;
  }

  static getWithNoPara(url, {data}) async {
    DateTime date1= new DateTime.now();
    print('get请求启动! url：$url ');
    Response response;
    try {
      response = await dio.get(
        url,
      );
      print('get请求成功!response.data：${response.headers}');
      print('get请求成功!response.data：${response.data}');
    } on DioError catch (e) {
      print(e.toString());
      if (CancelToken.isCancel(e)) {
        print('get请求取消! ' + e.message);
      }
      print('get请求发生错误：$e');
    }
    DateTime date2= new DateTime.now();

    int cost =date2.millisecondsSinceEpoch-date2.millisecondsSinceEpoch;

    print('get请求启动! url ,cost ：$url ** $cost');

    return response.data;
  }


  static post(url, {data, options, cancelToken}) async {
     DateTime date1= new DateTime.now();
    print('post请求启动! url：$url ,body: $data');
    Response response;
    try {
      response = await dio.post(
        url,
        data: data,
        cancelToken: cancelToken,
      );
      print('post请求成功!response.data：${response.data}');
    } on DioError catch (e) {
      if (CancelToken.isCancel(e)) {
        print('post请求取消! ' + e.message);
      }
      print('post请求发生错误：$e');
    }
     DateTime date2= new DateTime.now();
     int cost =date2.millisecondsSinceEpoch-date2.millisecondsSinceEpoch;


    return response.data;
  }


}